package com.jzo2o.customer.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jzo2o.common.model.CurrentUserInfo;
import com.jzo2o.customer.mapper.BankAccountMapper;
import com.jzo2o.customer.model.domain.BankAccount;
import com.jzo2o.customer.model.dto.request.BankAccountUpsertReqDTO;
import com.jzo2o.customer.service.IBankAccountService;
import com.jzo2o.mvc.utils.UserContext;
import org.springframework.stereotype.Service;

/**
 * @Author: wen
 * @Time: 2024-04-25 22:23
 * @Version: 1.0
 */
@Service
public class BankAccountServiceImpl extends ServiceImpl<BankAccountMapper, BankAccount> implements IBankAccountService {

    /**
     * 新增或更新
     *
     * @param dto 银行账号新增或更新模型
     */
    @Override
    public void upsert(BankAccountUpsertReqDTO dto) {

        if (ObjectUtil.isEmpty(dto)) {
            throw new ArithmeticException("参数不能为空");
        }
        // 获取当前用户信息
        CurrentUserInfo currentUserInfo = UserContext.currentUser();
        // 设置用户id
        dto.setId(currentUserInfo.getId());
        // 设置用户类型
        dto.setType(currentUserInfo.getUserType());
        // 类型转换
        BankAccount bankAccount = BeanUtil.toBean(dto, BankAccount.class);
        super.saveOrUpdate(bankAccount);
    }
}
